package com.zhida.jiyangcenter.utils

import android.content.Context
import android.graphics.BitmapFactory
import android.util.Log
import chooongg.base.manager.app
import chooongg.base.utils.isSpace
import chooongg.base.utils.resString
import chooongg.base.utils.toast
import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.PlatformActionListener
import cn.sharesdk.framework.ShareSDK
import com.zhida.jiyangcenter.R
import java.util.HashMap


fun share(
    mTargetScene: Int,
    webpageUrl: String,
    title: String,
    description: String,
    transaction: String
) {
    val titleTemp = if (isSpace(title)) app.resString(R.string.app_name) else title
    val sp = Platform.ShareParams()
    sp.shareType = mTargetScene
    sp.title = titleTemp
    sp.titleUrl = webpageUrl
    sp.url = webpageUrl
    sp.text = description

    val platform = ShareSDK.getPlatform(transaction)
    platform.platformActionListener = object : PlatformActionListener {
        override fun onComplete(platform: Platform?, i: Int, hashMap: HashMap<String, Any>?) {
        }

        override fun onCancel(platform: Platform?, i: Int) {
        }

        override fun onError(platform: Platform?, i: Int, throwable: Throwable?) {
            toast("分享失败")
            Log.e("fenxiang", "shibai", throwable)
        }
    }
    platform.share(sp)
}

fun buildTransaction(type: String?): String {
    return if (type == null) System.currentTimeMillis()
        .toString() else type + System.currentTimeMillis()
}